﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ThreadAndLock
{
    class Program
    {
        static void Main(string[] args)
        {
            Test test1 = new Test();
            Test test2 = new Test();
            Thread thread1 = new Thread(new ThreadStart(test1.increase));
            Thread thread2 = new Thread(new ThreadStart(test2.increase));
            thread1.Start();
            thread2.Start();
            Console.ReadKey();
        }

        private class Test
        {
            public int count;
            //synchronized修饰普通成员方法
            public  void increase()
            {
                lock(this)
                { 
                    for(int i = 0; i <1000; i++)
                    {
                        count++;
                        Console.WriteLine(count);
                    }              
                }
            }
        }

    }
}
